<?php
/**
 * Created by PhpStorm.
 * User: zlkmu
 * Date: 2017/8/29
 * Time: 13:58
 */
    require_once ('../Common.php');
    require_once ('../SQLBase.php');
    class FinanceManage{
        //辅助函数，添加报销项目
        function addFinanceItem($item, $item_type, $is_section){
            $con = new SQLBase();
            $query = "INSERT INTO fee_item(item_name, item_type, is_section) VALUES('$item', '$item_type', '$is_section')";
            $r = $con->queryData($query);
            if($r){
                return true;
            }
            return false;
        }
        //辅助函数，删除报销项目
        function delFinanceItem($itemID){
            $conn = new SQLBase();
            $query = "DELETE  FROM fee_item WHERE item_id = $itemID";

            $r = $conn->queryData($query);
            if($r){
                return true;
            }
            else{
                return false;
            }
        }

        //辅助函数，修改报销项目
        function modifyFinanceItem($itemID, $item_name, $item_type, $is_section){
            $conn = new SQLBase();
            $query = "UPDATE fee_item SET item_name = '$item_name', item_type = '$item_type' , is_section = '$is_section' WHERE item_id = '$itemID'";

            $r = $conn->queryData($query);
            if($r){
                return true;
            }
            else{
                return false;
            }
        }

        //辅助函数，获取报销项目
        function getAllFinanceItem(){
            $conn = new SQLBase();
            $query = "SELECT * FROM fee_item";
            $result_array = array();
            $r = $conn->queryData($query);
            if($r){
                $result_array['state'] = 1;
                $result_array['data'] = array();
                for($i = 0; $i < $r->num_rows; $i++){
                    $row = $r->fetch_array();
                    $result_array['data'][$i] = array('id'=>$row['item_id'], 'name'=>$row['item_name'],'type'=>$row['item_type'], 'is_section'=>$row['is_section']);
                }
            }
            else{
                $result_array['state'] = 0;
                $result_array['error'] = 'DB_ERROR';
            }

            return $result_array;
        }


    }


?>